<?php

class FinanceiroService extends Model {

    /**
     * @var FinanceiroDao
     */
    private $financeiroDao;
    /**
     * @var ClienteService
     */
    private $clienteService;
    /**
     * @var HistoricoSituacaoService
     */
    private $historicoSituacaoService;

    public function injectDependencies() {
        $this->financeiroDao = FinanceiroDao::getInstance();
        $this->clienteService = ClienteService::getInstance();
        $this->historicoSituacaoService = HistoricoSituacaoService::getInstance();
    }

    public function countMounthlyPaymentsByFinancial($IDFinanceiro) {
        return $this->financeiroDao->countMounthlyPaymentsByFinancial($IDFinanceiro);
    }

    public function getReceivedTotalValueFromFinancial($IDFinanceiro) {
        return $this->financeiroDao->getReceivedTotalValueFromFinancial($IDFinanceiro);
    }

    public function generateFinancialHistoryReport($IDFinanceiro) {
        return $this->financeiroDao->generateFinancialHistoryReport($IDFinanceiro);
    }

    public function countBillPaymentByFinancial($IDFinanceiro) {
        return $this->financeiroDao->countBillPaymentByFinancial($IDFinanceiro);
    }

    public function countCreditCardPaymentByFinancial($IDFinanceiro) {
        return $this->financeiroDao->countCreditCardPaymentByFinancial($IDFinanceiro);
    }

    public function countFrozenTimesByFinancial($IDFinanceiro) {
        return $this->financeiroDao->countFrozenTimesByFinancial($IDFinanceiro);
    }

    public function countPreFrozenTimesByFinancial($IDFinanceiro) {
        return $this->financeiroDao->countPreFrozenTimesByFinancial($IDFinanceiro);
    }

    public function countDelayTimesByFinancial($IDFinanceiro) {
        return $this->financeiroDao->countDelayTimesByFinancial($IDFinanceiro);
    }

    public function reverse($ArDados) {
        return $this->financeiroDao->reverseCustomer($ArDados['IDFinanceiro'], $ArDados['FoValor'], $ArDados['DtData']);
    }

    public function findPendingPaymentsByFinancial($IDFinanceiro) {
        return $this->financeiroDao->findPendingPaymentsByFinancial($IDFinanceiro);
    }

    public function releasePayment($ArDados) {
        return $this->financeiroDao->releasePayment($ArDados['Payments'], $ArDados['IDFinanceiro']);
    }

    public function generateDelinquentReport() {
        $ArCustomers = $this->clienteService->findAll();
        foreach($ArCustomers as $Customer) {
            $ReportCustomer = array(
                'ATRASO' => $Customer->countHistoryOf('ATRASO'),
                'PRE CONGELADO' => $Customer->countHistoryOf('PRE CONGELADO'),
                'CONGELADO' => $Customer->countHistoryOf('CONGELADO')
            );
            $Customer->setReport($ReportCustomer);
        }
        return $ArCustomers;
    }

    public function generateHeadLineDelinquentReport() {
        $ReportLines = array(
            'ATRASO' => $this->historicoSituacaoService->getHeadLineSituationFor('ATRASO'),
            'PRE CONGELADO' => $this->historicoSituacaoService->getHeadLineSituationFor('PRE CONGELADO'),
            'CONGELADO' => $this->historicoSituacaoService->getHeadLineSituationFor('CONGELADO')
        );
        foreach($ReportLines as &$Line) {
            $Line['Cliente'] = $this->clienteService->findByFinancial($Line['IDFinanceiro']);
        }
        return $ReportLines;
    }

    public function generatePaymentReport() {
        return array(
            'TEMPO' => $this->clienteService->findOldersActiveCustomerInSystem(5),
            'VALOR' => $this->findValueActiveCustomerInSystem(5),
            'PONTUAL' => $this->historicoSituacaoService->findPunctualCustomers(),
        );
    }

    public function findValueActiveCustomerInSystem($ItLimit) {
        $ArCustomers = $this->financeiroDao->findValueActiveCustomerInSystem($ItLimit);
        $this->clienteService->fillCustomer($ArCustomers);
        return $ArCustomers;
    }

    public function updateFinancialData($ArDados) {
        return $this->financeiroDao->update($ArDados);
    }

}

?>
